package com.wuwei.tms.setting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuwei.tms.pojo.Airplane;
import com.wuwei.tms.setting.mapper.AirplaneMapper;
import com.wuwei.tms.setting.service.AirplaneService;
import com.wuwei.tms.utils.result.Result;
import com.wuwei.tms.vo.BorrowExcel;
import com.wuwei.tms.workbench.mapper.BorrowMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AirplaneServiceImpl extends ServiceImpl<AirplaneMapper, Airplane> implements AirplaneService {

    @Resource
    AirplaneMapper airplaneMapper;

    @Resource
    BorrowMapper borrowMapper;

    /**
     * 创建飞机的时候不能和数据库中已经存在的飞机编号重复
     * @param airplane
     * @return
     */
    @Override
    public Result<String> addAirplane(Airplane airplane) {
        //如果创建的飞机号已经存在了，那就不能创建
        LambdaQueryWrapper<Airplane> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Airplane::getAirplane,airplane.getAirplane());
        int i = airplaneMapper.insert(airplane);
        if (i!=1){
            return Result.fail("创建失败！");
        }
        return Result.ok("创建成功！");
    }

    /**
     * 分页所有飞机列表并进行分页
     * @param currentPage
     * @param pageSize
     * @param airplane
     * @return
     */
    @Override
    public List<Airplane>listAndPagination(Integer currentPage, Integer pageSize, String airplane) {
        int offset = (currentPage-1)*pageSize;
        return airplaneMapper.myPagination(offset,pageSize,airplane);
    }
}
